//
//  ACEBaseTabBarController.m
//  ACE
//
//  Created by zhangtao on 2018/8/7.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "ACEBaseTabBarController.h"
#import "ACECourseViewController.h"
#import "ACEChatViewController.h"
#import "ACEQuestionsViewController.h"
#import "ACEStudyViewController.h"
#import "ACEMeViewController.h"
#import "ACECourseListViewController.h"
@interface ACEBaseTabBarController ()<UITabBarControllerDelegate,UITabBarDelegate>

@end

@implementation ACEBaseTabBarController

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    NSLog(@"%@",item.title);
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    if (viewController == self.viewControllers[0]) {
        ACECourseListViewController *list = [[ACECourseListViewController alloc]init];

        UINavigationController *nav = (UINavigationController *)viewController;
        [nav setViewControllers:@[list]];
    }
//    return NO;
    return YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    self.role = appRole_student;
    [self setStudentTabBarItem];
}

-(void)changeRole{
    if (self.role == appRole_student) {

        [self setTeacherTabBarItem];
        self.role = appRole_teacher;
    }else{

        [self setStudentTabBarItem];
        self.role = appRole_student;
    }
}

-(void)setStudentTabBarItem{
    UIColor *selectColor = RGB(48, 209, 97, 1);
    NSDictionary *titleNormal = @{NSForegroundColorAttributeName:[UIColor darkGrayColor]};
    NSDictionary *titleSelected = @{NSForegroundColorAttributeName:selectColor};
    
    
    ACECourseListViewController *list = [[ACECourseListViewController alloc]init];
    
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ACECourseViewController *course = [storyBoard instantiateViewControllerWithIdentifier:@"course"];
    ACEChatViewController *chat = [storyBoard instantiateViewControllerWithIdentifier:@"chat"];
    ACEQuestionsViewController *questions = [storyBoard instantiateViewControllerWithIdentifier:@"questions"];
    ACEStudyViewController *study = [storyBoard instantiateViewControllerWithIdentifier:@"study"];
    ACEMeViewController *me = [storyBoard instantiateViewControllerWithIdentifier:@"me"];
    
    
    UINavigationController *navCourse = [[UINavigationController alloc]initWithRootViewController:course];
    navCourse.tabBarItem.image = [[UIImage imageNamed:@"学生课程icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navCourse.tabBarItem.selectedImage = [[UIImage imageNamed:@"学生课程icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navCourse.tabBarItem setTitle:@"课程"];
    
    [navCourse.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navCourse.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    
    UINavigationController *navChat = [[UINavigationController alloc]initWithRootViewController:chat];
    navChat.tabBarItem.image = [[UIImage imageNamed:@"学生聊天icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navChat.tabBarItem.selectedImage = [[UIImage imageNamed:@"学生聊天icon选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navChat.tabBarItem setTitle:@"聊天"];
    [navChat.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navChat.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    UINavigationController *navQuestions = [[UINavigationController alloc]initWithRootViewController:questions];
    navQuestions.tabBarItem.image = [[UIImage imageNamed:@"学生题库icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navQuestions.tabBarItem.selectedImage = [[UIImage imageNamed:@"题库icon选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navQuestions.tabBarItem setTitle:@"题库"];
    [navQuestions.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navQuestions.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    
    UINavigationController *navStudy = [[UINavigationController alloc]initWithRootViewController:study];
    navStudy.tabBarItem.image = [[UIImage imageNamed:@"学生-学习"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navStudy.tabBarItem.selectedImage = [[UIImage imageNamed:@"学习选中icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navStudy.tabBarItem setTitle:@"学习"];
    [navStudy.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navStudy.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    
    UINavigationController *navMe = [[UINavigationController alloc]initWithRootViewController:me];
    navMe.tabBarItem.image = [[UIImage imageNamed:@"学生我的icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navMe.tabBarItem.selectedImage = [[UIImage imageNamed:@"学生我的icon选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navMe.tabBarItem setTitle:@"我的"];
    [navMe.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navMe.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    [self setViewControllers:@[navCourse,navChat,navQuestions,navStudy,navMe]];
}

-(void)setTeacherTabBarItem{
    UIColor *selectColor = RGB(152, 215, 246, 1);
    NSDictionary *titleNormal = @{NSForegroundColorAttributeName:[UIColor darkGrayColor]};
    NSDictionary *titleSelected = @{NSForegroundColorAttributeName:selectColor};
    
    
    ACECourseListViewController *list = [[ACECourseListViewController alloc]init];
    
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ACECourseViewController *course = [storyBoard instantiateViewControllerWithIdentifier:@"course"];
    ACEChatViewController *chat = [storyBoard instantiateViewControllerWithIdentifier:@"chat"];
    ACEQuestionsViewController *questions = [storyBoard instantiateViewControllerWithIdentifier:@"questions"];
    ACEStudyViewController *study = [storyBoard instantiateViewControllerWithIdentifier:@"study"];
    ACEMeViewController *me = [storyBoard instantiateViewControllerWithIdentifier:@"me"];
    
    
    UINavigationController *navCourse = [[UINavigationController alloc]initWithRootViewController:course];
    navCourse.tabBarItem.image = [[UIImage imageNamed:@"课程icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navCourse.tabBarItem.selectedImage = [[UIImage imageNamed:@"课程icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navCourse.tabBarItem setTitle:@"课程"];
    
    [navCourse.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navCourse.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    
    UINavigationController *navChat = [[UINavigationController alloc]initWithRootViewController:chat];
    navChat.tabBarItem.image = [[UIImage imageNamed:@"聊天icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navChat.tabBarItem.selectedImage = [[UIImage imageNamed:@"聊天icon copy选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navChat.tabBarItem setTitle:@"聊天"];
    [navChat.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navChat.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    
    UINavigationController *navStudy = [[UINavigationController alloc]initWithRootViewController:study];
    navStudy.tabBarItem.image = [[UIImage imageNamed:@"Group 4 Copy 2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navStudy.tabBarItem.selectedImage = [[UIImage imageNamed:@"Group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navStudy.tabBarItem setTitle:@"学习"];
    [navStudy.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navStudy.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    
    
    UINavigationController *navMe = [[UINavigationController alloc]initWithRootViewController:me];
    navMe.tabBarItem.image = [[UIImage imageNamed:@"我的icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navMe.tabBarItem.selectedImage = [[UIImage imageNamed:@"我的icon选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [navMe.tabBarItem setTitle:@"我的"];
    [navMe.tabBarItem setTitleTextAttributes:titleNormal forState:UIControlStateNormal];
    [navMe.tabBarItem setTitleTextAttributes:titleSelected forState:UIControlStateSelected];
    
    [self setViewControllers:@[navCourse,navChat,navStudy,navMe]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
